package HeiMa.CollectionStudy.单列;

import java.awt.*;

public class Color {
    private static final Color RED = new Color("红色");
    private static final Color GREEN = new Color("绿色");
    private static final Color BLUE = new Color("蓝色");
    private String title;
    private Color(String title){
        this.title = title;
    }
    public static Color getInstance(String color){
        switch (color){
            case "red" : return RED;
            case "green" : return GREEN;
            case "blue" : return BLUE;
            default: return null;
        }
    }

    @Override
    public String toString() {
        return this.title;
    }
}

class JavaDemo{
    public static void main(String[] args) {
        Color c = Color.getInstance("green");
        System.out.println(c);
    }
}
